        var statStore = new Ext.data.JsonStore({
    		url: '/weihe/getList_stat',
			root: 'datas',
			fields : [{
			        	   name:'StatId',mapping:'id'
			          },{
			        	   name:'StatBank',mapping:'bank' 
			          },{
        				   name:'StatWay',mapping:'way'
        			  },{
        				   name:'StatExposure',mapping:'exposure'
        			  },{
        				   name:'StatFacility',mapping:'facility'
        			  },{
        				   name:'StatUsed',mapping:'used'
        			  }],
						listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_stat',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}

		});
        
        var statItemStore = new Ext.data.JsonStore({
			url: '/weihe/getItems_stat',
			root: 'datas',
			fields : [{
			        	   name:'StatItemId',mapping:'id'
			          },{
			        	   name:'StatItemCode',mapping:'code' 
			          },{
        				   name:'StatItemLendDate', mapping:'lendDate',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'StatItemReturnDate', mapping:'returnDate',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'StatItemTerm',mapping:'term'
        			  },{
        				   name:'StatItemRmoney',mapping:'rmoney'
        			  },{
        				   name:'StatItemDmoney',mapping:'dmoney'
        			  },{
        				   name:'StatItemRate',mapping:'rate'
        			  },{
        				   name:'StatItemGuaranty',mapping:'guaranty'
        			  }],
						listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_stat',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
		
		var statDbStore = new Ext.data.JsonStore({
			url: '/weihe/getDbs_stat',
			root: 'datas',
			fields : [{
			        	   name:'StatDbId',mapping:'id'
			          },{
			        	   name:'StatDbCode',mapping:'code' 
			          },{
        				   name:'StatDbRepayDate', mapping:'repayDate',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'StatDbMoney',mapping:'money'
        			  },{
        				   name:'StatDbTax',mapping:'tax'
        			  }],
						listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_stat',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
		
			var statAcStore = new Ext.data.JsonStore({
			url: '/weihe/getAcs_stat',
			root: 'datas',
			fields : [{
			        	   name:'StatAcId',mapping:'id'
			          },{
        				   name:'StatAcDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
        			  },{
			        	   name:'StatAcCode',mapping:'code' 
			          },{
			        	   name:'StatAcCompany',mapping:'company' 
			          },{
        				   name:'StatAcMoney',mapping:'money'
        			  },{
        				   name:'StatAcBail',mapping:'bail'
        			  },{
        				   name:'StatAcBalance',mapping:'balance'
        			  },{
        				   name:'StatAcTerm',mapping:'term'
        			  },{
        				   name:'StatAcAcDate', mapping:'acDate',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'StatAcRepayDate', mapping:'repayDate',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'StatAcSaveDate', mapping:'saveDate',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'StatAcAcCode',mapping:'acCode'
        			  },{
        				   name:'StatAcBailRate',mapping:'bailRate'
        			  },{
        				   name:'StatAcSaveDsc',mapping:'saveDsc'
        			  },{
        				   name:'StatAcLastDate', mapping:'lastDate',type : 'date', dateFormat:"Y-m-d"
        			  }],
						listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_stat',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
        
       
        
stats = function(){
	
	var tmp='';

	
  return{
	  

listForm : function(){
	  
    


		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
				progressConsole();
				if(listForm.form.isValid()){ 
					if (listForm.form.findField("StatId").getValue() == "") {
						 listForm.form.submit({
						     url : '/weihe/add_stat',
						     success : function(form, action) {
							       if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								   }else{
								        Ext.Msg.alert('消息', action.result.msg, function() {
								        Ext.getCmp("statForm").form.reset();
									    Ext.getCmp("statGrid").getStore().load({params : {start : 0, limit : 10}});
								        })
							       }
						     }
					      })
					}else {
							listForm.form.submit({
								url : '/weihe/update_stat',
								success : function(form, action) {
									if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								    }else{
										Ext.Msg.alert('消息', action.result.msg, function() {
											Ext.getCmp("statGrid").getStore().load({params : {start : 0, limit : 10}});
										})
									}
							   }
							})
					}
				}else{
					Ext.Msg.alert('提示','请输入相关内容');
				}
			}
		});

	var button_clear = new Ext.Button({
		text : '清空',
		handler : function() {
		
			listForm.form.reset();
			listForm.buttons[0].setText('添加');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = listForm.form.findField('StatId').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/delete_stat',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("statGrid").getStore().load({params : {start : 0, limit : 10}});
								listForm.form.reset();
								listForm.buttons[0].setText('添加');
							});
						}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'stat.id' : listForm.form.findField('StatId').getValue() }
				});
			}
		}
	});
	
		  
	
			 var wayComboData = new Ext.data.SimpleStore({
				fields : ['text'],
				data : [['提单押汇'],['退税'],['银承']]
			});
	  
			var listForm = new Ext.form.FormPanel({
			id : 'statForm',
			region : 'east',
			title : '贷款信息',
			frame : true,
			width : 300,
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 60,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				id: 'StatId',
				xtype : 'hidden',
				name : 'stat.id'
			},{
				id: 'StatBank',
				fieldLabel: "授信行",
				name: "stat.bank"
			},{
				id:'StatWay',
				fieldLabel : '贷款方式',
				hiddenName : 'stat.way',
				xtype : 'combo',
				store : wayComboData,
				emptyText : '请选择',
				mode : 'local',
				triggerAction : 'all',
				allowBlank:false,
				editable: false,
				displayField : 'text'
			},{
				id:'StatExposure',
				fieldLabel : '授信敞口',
				name : 'stat.exposure',
				regex : /^\d+(\.\d+)?$/,
			    regexText:'请输入有效的价格' 
			},{
				id:'StatFacility',
				fieldLabel : '授信额度',
				name : 'stat.facility',
				regex : /^\d+(\.\d+)?$/,
			    regexText:'请输入有效的价格' 
			}],
			buttons : [button_add,button_clear,button_del]
	});
	  
	  return listForm;
},  
	  
	  
  listGrid : function(){
	  
		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 10,
			store : statStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var listGrid = new Ext.grid.GridPanel({
		   id:'statGrid',
		   title : '贷款信息表',
		   region : 'center',
		   minColumnWidth : 35,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : statStore,
		   columns: [
		             {header : '授信行', dataIndex : 'StatBank'},
		             {header : '贷款方式', dataIndex : 'StatWay'},
		             {header : '授信敞口', dataIndex : 'StatExposure'},
		             {header : '授信额度', dataIndex : 'StatFacility'},
		             {header : '借入', dataIndex : 'StatUsed'}
		             ],
         sm : rowSelectionModel,
         listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   		var record = grid.getStore().getAt(rowIndex);
			   		tmp = record.id;
			   		Ext.getCmp("statForm").form.loadRecord(record);
					Ext.getCmp("statForm").buttons[0].setText('修改');
		   		},'rowdblclick':function(grid, rowIndex, event) {
			   		var record = grid.getStore().getAt(rowIndex);
			   		if(record.get('StatWay') == "提单押汇"){
				   		stats.statWin().show();
				   		Ext.getCmp("statItemGrid").getStore().baseParams = {'stat.id': record.id};
				   		Ext.getCmp("statItemGrid").getStore().load({params : {start : 0, limit : 8}});
			   		}else if(record.get('StatWay') == "退税"){
			   			stats.statDbGridWin().show();
				   		Ext.getCmp("statDbGrid").getStore().baseParams = {'stat.id': record.id};
				   		Ext.getCmp("statDbGrid").getStore().load({params : {start : 0, limit : 8}});
			   		}else if(record.get('StatWay') == "银承"){
			   			stats.statAcGridWin().show();
				   		Ext.getCmp("statAcGrid").getStore().baseParams = {'stat.id': record.id};
				   		Ext.getCmp("statAcGrid").getStore().load({params : {start : 0, limit : 8}});
			   		}
		   		}
		   },
		  bbar : pageToolBar
});
		return listGrid;
	},
	
	
	
	statWin : function(){
  	  var statWin = new Ext.Window({
  	  	id: 'statWin',
        title : '明细信息表',
        layout: 'fit',
        width:600,    
        height:400,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[stats.statGrid()] 
        
    });  
  		return statWin;
  	},
  
    statGrid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 8,
			store : statItemStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var grid = new Ext.grid.GridPanel({
		   id:'statItemGrid',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : statItemStore,
		    tbar:["-",{
	   						text:"添加",
								handler:function(){
									 Ext.getCmp("statWin").hidden = true;
									 stats.statItemWin().show();
									 Ext.getCmp("statItemForm").form.findField('stat.id').setValue(tmp);
								}
	   					},"-",{
	   						text:"修改",
								handler:function(){
									var sm = Ext.getCmp("statItemGrid").getSelectionModel();
							        var record = sm.getSelected();
	         					    if (sm.hasSelection()){
										 Ext.getCmp("statWin").hidden = true;
										 stats.statItemWin().show();
										 Ext.getCmp("statItemForm").form.loadRecord(record);
										 Ext.getCmp("statItemForm").form.findField('stat.id').setValue(tmp);
	         					    }else{
	         					    	Ext.Msg.alert('提示','请选择修改项');
	         					    }
         					   
							   }
	   			},"-",{
	   						text:"删除",
								handler:function(){
									var sm = Ext.getCmp("statItemGrid").getSelectionModel();
							        var record = sm.getSelected();
									if (!sm.hasSelection()) {
										Ext.Msg.alert('提示', '请选择需要删除的信息!');
									} else {
										var id = record.id;
										progressConsole();
										Ext.Ajax.request({
											url : '/weihe/deleteItem_stat',
											success : function(response) {
												var json = Ext.decode(response.responseText);
													if (json.success) {
														if (json.deny) {
														Ext.Msg.alert('错误', json.msg);
													 }else{
															Ext.Msg.alert('消息', json.msg, function() {
															Ext.getCmp("statGrid").getStore().reload();
										  					Ext.getCmp("statItemGrid").getStore().reload();
														});
													}
												  }else{
													Ext.Msg.alert('消息', json.msg);
												  }
											},
											failure : function() {
												Ext.Msg.alert('错误', '删除失败!');
											},
											params: { 'statItem.id': id , 'stat.id' : tmp}
						
										});
									}
								
								}
	   			},"-"],
		   columns: [
		             {header : '协议号', dataIndex : 'StatItemCode'},
		             {header : '借款期', dataIndex : 'StatItemLendDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y-m-d')},
		             {header : '还款期', dataIndex : 'StatItemReturnDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y-m-d')},
		             {header : '借款期限(天)', dataIndex : 'StatItemTerm',renderer:function(value){
																						if(value != 0){
																								return value;
																							}else{
																								return '';
																							}
		             }},
		             {header : '贷款金额(人民币)', dataIndex : 'StatItemRmoney'},
		             {header : '贷款金额(美金)', dataIndex : 'StatItemDmoney'},
		             {header : '贷款利率', dataIndex : 'StatItemRate',renderer:function(value){
																						if(value != 0){
																								return value;
																							}else{
																								return '';
																							}
		             }},
		             {header : '抵押物及价值', dataIndex : 'StatItemGuaranty'}
        ],
           sm : rowSelectionModel,
           listeners :{ 
				'rowdblclick':function(grid, rowIndex, event) {
				   		var record = grid.getStore().getAt(rowIndex);
				   		if(record.get('StatItemCode')!= "合计"){
				   			 Ext.getCmp("statWin").hidden = true;
							stats.statItemWin().show();
							Ext.getCmp("statItemForm").form.loadRecord(record);
						    Ext.getCmp("statItemForm").form.findField('stat.id').setValue(tmp);
				   		}else{
				   			Ext.Msg.alert("提示","不能编辑合计数据");
				   		}
			   		}
		   		
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	},
	
	
		
	statItemWin : function(){
  	  var statItemWin = new Ext.Window({
  	  	id: 'statItemWin',
        title : '明细信息表',
        layout: 'fit',
        width:300,    
        height:400,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[stats.statsForm()] 
        
    });  
  		return statItemWin;
  	},
	
	
	statsForm : function(){
		
		

		var button = new Ext.Button({
			text : '确定',
			handler : function() {
					progressConsole();
				if(statsForm.form.isValid()){ 	
					if (statsForm.form.findField("statItem.id").getValue() == "") {
						statsForm.form.submit({
						  url : '/weihe/addItem_stat',
						   success : function(form, action) {
							if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
							}else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									  Ext.getCmp("statGrid").getStore().reload();
									  Ext.getCmp("statItemGrid").getStore().reload();
									   Ext.getCmp("statItemWin").close();
									   statsForm.form.reset();
									   
								});
							  }
						    },
						    failure : function(form, action) {
      							Ext.Msg.alert('错误', action.result.msg);
      						}
					    });
					}else {
						statsForm.form.submit({
							  url : '/weihe/updateItem_stat',
							   success : function(form, action) {
								 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										var i = statsForm.form.findField('stat.id').getValue();
										  Ext.getCmp("statGrid").getStore().reload();
									  	  Ext.getCmp("statItemGrid").getStore().reload();
									      Ext.getCmp("statItemWin").close();
									      statsForm.form.reset();
									});
								  }
							    },
							    failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
						    });
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	
		var statsForm = new Ext.form.FormPanel({
			id : 'statItemForm',
			frame : true,
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 60,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				id: 'StatItemId',
				xtype : 'hidden',
				name : 'statItem.id'
			},{
				xtype : 'hidden',
				name : 'stat.id'
			},{
				id:'StatItemCode',
				fieldLabel : '协议号',
				allowBlank:false,
				name : 'statItem.code',
				blankText:'请输入协议号'
			},{
				id: 'StatItemLendDate',
                xtype: 'datefield',
                fieldLabel: "借款期",
                format : 'Y-m-d',
    			allowBlank:false,
                name: "statItem.lendDate"
			},{
				id: 'StatItemReturnDate',
                xtype: 'datefield',
                fieldLabel: "还款期",
                format : 'Y-m-d',
    			allowBlank:false,
                name: "statItem.returnDate"
			},{
				id:'StatItemTerm',
				fieldLabel : '借款期限',
				name : 'statItem.term'
			},{
				id:'StatItemRmoney',
				fieldLabel : '贷款金额(人民币)',
				name : 'statItem.rmoney'
			},{
				id:'StatItemDmoney',
				fieldLabel : '贷款金额(美金)',
				name : 'statItem.dmoney'
			},{
				id:'StatItemRate',
				fieldLabel : '贷款利率(%)',
				name : 'statItem.rate'
			},{
				id:'StatItemGuaranty',
				fieldLabel : '抵押物',
				name : 'statItem.guaranty'
				
			}],
			buttons : [button]
		
	});
		return statsForm;
	},

    statDbWin : function(){
  	  var statDbWin = new Ext.Window({
  	  	id: 'statDbWin',
        title : '明细信息表',
        layout: 'fit',
        width:300,    
        height:400,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[stats.statDbForm()] 
        
    });  
  		return statDbWin;
  	},
  	
    statDbGridWin : function(){
  	  var statWin = new Ext.Window({
  	  	id: 'statDbGridWin',
        title : '明细信息表',
        layout: 'fit',
        width:600,    
        height:400,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[stats.statDbGrid()] 
        
    });  
  		return statWin;
  	},
  
	
  	    statDbGrid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 8,
			store : statDbStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var grid = new Ext.grid.GridPanel({
		   id:'statDbGrid',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : statDbStore,
		    tbar:["-",{
	   						text:"添加",
								handler:function(){
									 Ext.getCmp("statDbGridWin").hidden = true;
									 stats.statDbWin().show();
									 Ext.getCmp("statDbForm").form.findField('stat.id').setValue(tmp);
								}
	   					},"-",{
	   						text:"修改",
								handler:function(){
									var sm = Ext.getCmp("statDbGrid").getSelectionModel();
							        var record = sm.getSelected();
	         					    if (sm.hasSelection()){
										 Ext.getCmp("statDbGridWin").hidden = true;
										 stats.statDbWin().show();
										 Ext.getCmp("statDbForm").form.loadRecord(record);
										 Ext.getCmp("statDbForm").form.findField('stat.id').setValue(tmp);
	         					    }else{
	         					    	Ext.Msg.alert('提示','请选择修改项');
	         					    }
         					   
							   }
	   			},"-",{
	   						text:"删除",
								handler:function(){
									var sm = Ext.getCmp("statDbGrid").getSelectionModel();
							        var record = sm.getSelected();
									if (!sm.hasSelection()) {
										Ext.Msg.alert('提示', '请选择需要删除的信息!');
									} else {
										var id = record.id;
										progressConsole();
										Ext.Ajax.request({
											url : '/weihe/deleteDb_stat',
											success : function(response) {
												var json = Ext.decode(response.responseText);
													if (json.success) {
														if (json.deny) {
															Ext.Msg.alert('错误', json.msg);
														
													 }else{
														Ext.Msg.alert('消息', json.msg, function() {
															Ext.getCmp("statGrid").getStore().reload();
										  					Ext.getCmp("statDbGrid").getStore().reload();
										  				});
													}
												  }else{
													Ext.Msg.alert('消息', json.msg);
												  }
											},
											failure : function() {
												Ext.Msg.alert('错误', '删除失败!');
											},
											params: { 'statDb.id': id , 'stat.id' : tmp}
						
										});
									}
								
								}
	   			},"-"],
		   columns: [
		             {header : '接单号', dataIndex : 'StatDbCode'},
		             {header : '退税金额', dataIndex : 'StatDbTax'},
		             {header : '贷款金额(人民币)', dataIndex : 'StatDbMoney'},
		             {header : '还款日期', dataIndex : 'StatDbRepayDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y-m-d')}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			'rowdblclick':function(grid, rowIndex, event) {
			   		var record = grid.getStore().getAt(rowIndex);
			   			if(record.get('StatDbCode')!= "合计"){
				   			 Ext.getCmp("statWin").hidden = true;
							stats.statDbWin().show();
							Ext.getCmp("statDbForm").form.loadRecord(record);
					    	Ext.getCmp("statDbForm").form.findField('stat.id').setValue(tmp);
				   		}else{
				   			Ext.Msg.alert("提示","不能编辑合计数据");
				   		}
			}
		   		
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	},
  	
  		statDbForm : function(){
		
		

		var button = new Ext.Button({
			text : '确定',
			handler : function() {
					progressConsole();
				if(statsForm.form.isValid()){ 	
					if (statsForm.form.findField("statDb.id").getValue() == "") {
						statsForm.form.submit({
						  url : '/weihe/addDb_stat',
						   success : function(form, action) {
							if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
							}else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									  Ext.getCmp("statGrid").getStore().reload();
									  Ext.getCmp("statDbGrid").getStore().reload();
									   Ext.getCmp("statDbWin").close();
									   statsForm.form.reset();
									   
								});
							  }
						    },
						    failure : function(form, action) {
      							Ext.Msg.alert('错误', action.result.msg);
      						}
					    });
					}else {
						statsForm.form.submit({
							  url : '/weihe/updateDb_stat',
							   success : function(form, action) {
								 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										var i = statsForm.form.findField('stat.id').getValue();
										  Ext.getCmp("statGrid").getStore().reload();
									  	  Ext.getCmp("statDbGrid").getStore().reload();
									      Ext.getCmp("statDbWin").close();
									      statsForm.form.reset();
									});
								  }
							    },
							    failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
						    });
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	
		var statsForm = new Ext.form.FormPanel({
			id : 'statDbForm',
			frame : true,
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 60,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				id: 'StatDbId',
				xtype : 'hidden',
				name : 'statDb.id'
			},{
				xtype : 'hidden',
				name : 'stat.id'
			},{
				id:'StatDbCode',
				fieldLabel : '接单号',
				allowBlank:false,
				name : 'statDb.code',
				blankText:'请输入接单号'
			},{
				id:'StatDbTax',
				fieldLabel : '退税金额',
				name : 'statDb.tax'
			},{
				id:'StatDbMoney',
				fieldLabel : '贷款金额',
				name : 'statDb.money'
			},{
				id: 'StatDbRepayDate',
                xtype: 'datefield',
                fieldLabel: "还款日期",
                format : 'Y-m-d',
    			allowBlank:false,
                name: "statDb.repayDate"
			}],
			buttons : [button]
		
	});
		return statsForm;
	},
	
	
	statAcWin : function(){
  	  var statAcWin = new Ext.Window({
  	  	id: 'statAcWin',
        title : '明细信息表',
        layout: 'fit',
        width:360,    
        height:400,
        modal: true,
        autoScroll : true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[stats.statAcForm()] 
        
    });  
  		return statAcWin;
  	},
  	
    statAcGridWin : function(){
  	  var statWin = new Ext.Window({
  	  	id: 'statAcGridWin',
        title : '明细信息表',
        layout: 'fit',
        width:600,    
        height:400,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[stats.statAcGrid()] 
        
    });  
  		return statWin;
  	},
  
	
  	    statAcGrid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 8,
			store : statAcStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var grid = new Ext.grid.GridPanel({
		   id:'statAcGrid',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : statAcStore,
		    tbar:["-",{
	   						text:"添加",
								handler:function(){
									 Ext.getCmp("statAcGridWin").hidden = true;
									 stats.statAcWin().show();
									 Ext.getCmp("statAcForm").form.findField('stat.id').setValue(tmp);
								}
	   					},"-",{
	   						text:"修改",
								handler:function(){
									var sm = Ext.getCmp("statAcGrid").getSelectionModel();
							        var record = sm.getSelected();
	         					    if (sm.hasSelection()){
										 Ext.getCmp("statAcGridWin").hidden = true;
										 stats.statAcWin().show();
										 Ext.getCmp("statAcForm").form.loadRecord(record);
										 Ext.getCmp("statAcForm").form.findField('stat.id').setValue(tmp);
	         					    }else{
	         					    	Ext.Msg.alert('提示','请选择修改项');
	         					    }
         					   
							   }
	   			},"-",{
	   						text:"删除",
								handler:function(){
									var sm = Ext.getCmp("statAcGrid").getSelectionModel();
							        var record = sm.getSelected();
									if (!sm.hasSelection()) {
										Ext.Msg.alert('提示', '请选择需要删除的信息!');
									} else {
										var id = record.id;
										progressConsole();
										Ext.Ajax.request({
											url : '/weihe/deleteAc_stat',
											success : function(response) {
												var json = Ext.decode(response.responseText);
													if (json.success) {
														if (json.deny) {
															Ext.Msg.alert('错误', json.msg);
														
													 }else{
														Ext.Msg.alert('消息', json.msg, function() {
															Ext.getCmp("statGrid").getStore().reload();
										  					Ext.getCmp("statAcGrid").getStore().reload();
										  				});
													}
												  }else{
													Ext.Msg.alert('消息', json.msg);
												  }
											},
											failure : function() {
												Ext.Msg.alert('错误', '删除失败!');
											},
											params: { 'statAc.id': id , 'stat.id' : tmp}
						
										});
									}
								
								}
	   			},"-"],
		   columns: [
		             {header : '出票日期', dataIndex : 'StatAcDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y-m-d')},
		             {header : '承兑合同号', dataIndex : 'StatAcCode'},
		             {header : '单位', dataIndex : 'StatAcCompany'},
		             {header : '票面金额', dataIndex : 'StatAcMoney'},
		             {header : '保证金', dataIndex : 'StatAcBail'},
		             {header : '差额', dataIndex : 'StatAcBalance',renderer:function(value){
																						if(value != 0){
																								return value;
																							}else{
																								return '';
																							}
		             }},
		             {header : '汇票期限', dataIndex : 'StatAcTerm'},
		             {header : '承兑到期时间', dataIndex : 'StatAcAcDate',renderer:Ext.util.Format.dateRenderer('Y-m-d')},
		             {header : '还款时间', dataIndex : 'StatAcRepayDate',renderer:Ext.util.Format.dateRenderer('Y-m-d')},
		             {header : '存入日期', dataIndex : 'StatAcSaveDate',renderer:Ext.util.Format.dateRenderer('Y-m-d')},
		             {header : '银承票号', dataIndex : 'StatAcAcCode'},
		             {header : '保证金比例', dataIndex : 'StatAcBailRate',renderer:function(value){
																						if(value != 0){
																								return value;
																							}else{
																								return '';
																							}
		             }},
		             {header : '定期存单日期', dataIndex : 'StatAcSaveDsc'},
		             {header : '存单到期日期', dataIndex : 'StatAcLastDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y-m-d')}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			'rowdblclick':function(grid, rowIndex, event) {
			   		var record = grid.getStore().getAt(rowIndex);
			   		 if(record.get('StatAcCode')){ 
			   		    Ext.getCmp("statAcGridWin").hidden = true;
						stats.statAcWin().show();
						Ext.getCmp("statAcForm").form.loadRecord(record);
					    Ext.getCmp("statAcForm").form.findField('stat.id').setValue(tmp);
					  }else{
					  	Ext.Msg.alert('提示','不能编辑合计数据');
					  }
			   			
					    
			   		}
		   		
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	},
  	
  		statAcForm : function(){
		
		

		var button = new Ext.Button({
			text : '确定',
			handler : function() {
					progressConsole();
				if(statsForm.form.isValid()){ 	
					if (statsForm.form.findField("statAc.id").getValue() == "") {
						statsForm.form.submit({
						  url : '/weihe/addAc_stat',
						   success : function(form, action) {
							if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
							}else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									  Ext.getCmp("statGrid").getStore().reload();
									  Ext.getCmp("statAcGrid").getStore().reload();
									   Ext.getCmp("statAcWin").close();
									   statsForm.form.reset();
									   
								});
							  }
						    },
						    failure : function(form, action) {
      							Ext.Msg.alert('错误', action.result.msg);
      						}
					    });
					}else {
						statsForm.form.submit({
							  url : '/weihe/updateAc_stat',
							   success : function(form, action) {
								 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										var i = statsForm.form.findField('stat.id').getValue();
										  Ext.getCmp("statGrid").getStore().reload();
									  	  Ext.getCmp("statAcGrid").getStore().reload();
									      Ext.getCmp("statAcWin").close();
									      statsForm.form.reset();
									});
								  }
							    },
							    failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
						    });
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	
		var statsForm = new Ext.form.FormPanel({
			id : 'statAcForm',
			frame : true,
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 90,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				id: 'StatAcId',
				xtype : 'hidden',
				name : 'statAc.id'
			},{
				xtype : 'hidden',
				name : 'stat.id'
			},{
				id: 'StatAcDate',
                xtype: 'datefield',
                fieldLabel: "出票时间",
                format : 'Y-m-d',
    			allowBlank:false,
                name: "statAc.date"
			},{
				id:'StatAcCode',
				fieldLabel : '承兑合同号',
				allowBlank:false,
				name : 'statAc.code',
				blankText:'请输入承兑合同号'
			},{
				id:'StatAcCompany',
				fieldLabel : '单位',
				allowBlank:false,
				name : 'statAc.company',
				blankText:'请输入单位'
			},{
				id:'StatAcMoney',
				fieldLabel : '票面金额',
				name : 'statAc.money'
			},{
				id:'StatAcBail',
				fieldLabel : '保证金',
				name : 'statAc.bail'
			},{
				id:'StatAcBalance',
				fieldLabel : '差额',
				name : 'statAc.balance'
			},{
				id:'StatAcTerm',
				fieldLabel : '汇票期限',
				name : 'statAc.term'
			},{
				id: 'StatAcAcDate',
                xtype: 'datefield',
                fieldLabel: "承兑到期时间",
                format : 'Y-m-d',
    			allowBlank:false,
                name: "statAc.acDate"
			},{
				id: 'StatAcRepayDate',
                xtype: 'datefield',
                fieldLabel: "还款时间",
                format : 'Y-m-d',
    			allowBlank:false,
                name: "statAc.repayDate"
			},{
				id: 'StatAcSaveDate',
                xtype: 'datefield',
                fieldLabel: "保证金存入日期",
                format : 'Y-m-d',
    			allowBlank:false,
                name: "statAc.saveDate"
			},{
				id:'StatAcAcCode',
				fieldLabel : '银承票号',
				name : 'statAc.acCode'
			},{
				id:'StatAcBailRate',
				fieldLabel : '保证金比例(%)',
				name : 'statAc.bailRate'
			},{
				id:'StatAcSaveDsc',
				fieldLabel : '定期存单存入日期',
				name : 'statAc.saveDsc'
			},{
				id: 'StatAcLastDate',
                xtype: 'datefield',
                fieldLabel: "存单到期日",
                format : 'Y-m-d',
    			allowBlank:false,
                name: "statAc.lastDate"
			}],
			buttons : [button]
		
	});
		return statsForm;
	}
	
  }
}();








